<template>
  <!-- 估价单选择 -->
  <div>
    <TopFilter ref="formpanel" :list="formList" labelWidth="100" @formChange="formchangeFun" />
    <FilterTable
      ref="basetables"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      selectionType="single"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :height="'200'"
      :onSyncTableData="tablechangeFun"
      :onRowSelectChange="selectchange"
      columnsRef="zjfygjestimate"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9999,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="confirmHandle">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { getrepairEstimateNOList } from '@/api/repair/business/evaluation/index';
export default {
  name: 'zjestimate',
  props: ['getdata'],
  data() {
    return {
      fetchApi: getrepairEstimateNOList,
      fetchParams: {
        sort: 'RO_NO',
        order: 'asc',
        limit: '10',
        offset: 0,
        repairEstimateList: '',
        dmsFuncId: '35100030',
        _: '1566282016273'
      },
      selectlist: [],
      formList: this.createFrom(),
      columns: this.createTable()
    };
  },
  created() {
    console.log(this.getdata);
    if (!this.getdata.estimateNo) {
      this.formList[0].initialValue = this.getdata.estimateNo || '';
    }
    if (!this.getdata.license) {
      this.formList[1].initialValue = this.getdata.license || '';
    }
  },
  methods: {
    createFrom() {
      return [
        {
          type: 'INPUT',
          label: '估价单号',
          fieldName: 'estimateNo',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          initialValue: ''
        }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '估价单号',
          dataIndex: 'ESTIMATE_NO',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.ESTIMATE_NO}</span>;
          }
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.REPAIR_TYPE_NAME}</span>;
          }
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.LICENSE}</span>;
          }
        },
        {
          title: '车主',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.OWNER_NAME}</span>;
          }
        },
        {
          title: '服务工程师',
          dataIndex: 'EMPLOYEE_NAME',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.EMPLOYEE_NAME}</span>;
          }
        },
        {
          title: '时间',
          dataIndex: 'CHECK_END_TIME',
          sorter: true,
          filter: true,
          hidden: true,
          render: props => {
            return <span>{!props.row.CHECK_END_TIME ? '' : props.row.CHECK_END_TIME}</span>;
          }
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.RO_CREATE_DATE}</span>;
          }
        },
        {
          title: '操作员',
          dataIndex: 'SERVICE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.SERVICE}</span>;
          }
        }
      ];
    },
    formchangeFun(val) {
      console.log(val, '搜索');
      this.fetchParams = Object.assign({}, val, this.fetchParams);
    },
    tablechangeFun(val) {},
    selectchange(val) {
      console.log(val, '选中');
      if (val && val.length > 0) {
        this.selectlist = val[0];
      } else {
        this.selectlist = [];
      }
    },
    // 关闭一级交互
    closeDialog() {
      console.log('关闭一级交互');
      this.$emit('close', false);
    },
    confirmHandle() {
      console.log(this.selectlist);
      if (this.selectlist.length <= 0) {
        return this.$notify({
          title: '提示信息',
          message: '数量不能为空，且必须大于 0',
          type: 'error'
        });
      }
      this.$emit('changedata', this.selectlist);
    }
  }
};
</script>
